<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${projectName}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript"
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<script src="<c:url value='/js/jquery.ui.widget.js'></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>"></script>
<script src="<c:url value='/js/jquery.fileupload.js'></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>"></script>
<script src="<c:url value='/js/server/rqfCommon.js'></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>"></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

#detailPan {
	width: 100%;
	height: 100%;
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.level1Class {
	margin-left: 10px;
}

.level2Class {
	margin-left: 30px;
}

.level3Class {
	margin-left: 50px;
}

.deepDark {
	background-color: #CCC488;
}

.normalDark {
	background-color: #FFF7BB;
}

.lowDark {
	
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}
.file {
	position: relative;
	display: inline-block;
	background: #1e519f;
	/*border: 1px solid #99D3F5;*/
	border-radius: 4px;
	/* padding: 4px 12px; */
	overflow: hidden;
	color: #1E88C7;
	text-decoration: none;
	text-indent: 0;
	line-height: 20px;
	cursor: pointer !important;
}
.file input {
	position: absolute;
	font-size: 100px;
	right: 0;
	top: 0;
	opacity: 0;
	cursor: pointer;
}

.file:hover {
	background: #ccc;
	text-decoration: none;
}
.import_style{
	width: 100%;
	height: 140px;
}
#importBtn {
	width: 75px;
	height: 20px;
	color: white;
	text-align: center;
	margin-left: 5px;
	margin-right: auto;
	margin-top: 0px;
}

.nameTitle {
	color: red;
}
</style>
<script type="text/javascript">
	var radioValue = [ {
		id : 1,
		text : "在职"
	}, {
		id : 0,
		text : "已离职"
	} ];
	var sexData = [ {
		id : 1,
		text : "男"
	}, {
		id : 0,
		text : "女"
	} ];
	var natureData = [ {
		id : 1,
		text : "长期"
	}, {
		id : 0,
		text : "短期"
	} ];
</script>

</head>
<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td width="240px"><a class="mini-button" id="rebackBtn"
					plain="true" iconCls="icon-list" onclick="status1">返回列表</a> 企业：<span
					class="nameTitle">未选择</span></td>
				<td><span id="separatorId" class="separator">&nbsp;&nbsp;
						<div id="typeBtn" class="mini-radiobuttonlist" repeatItems="1"
							repeatLayout="table" repeatDirection="vertical"
							style="float: left; margin-top: 4px;" textField="text"
							valueField="id" value="1" onvaluechanged="chageState"
							data="radioValue"></div>入职日期:&nbsp;&nbsp;<input id="starting"
						class="mini-datepicker" style="width: 100px;" showNullItem="false"
						valueField="" onvalidation="" allowInput="false"
						emptyText="起始期间..." nullItemText="&lt;无&gt;" /> <span
						style="vertical-align: middle; margin: auto 5px; display: inline-block;">至</span>
						<input id="ending" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="截止期间..." nullItemText="&lt;无&gt;" />
						<a class="mini-button" id="seachOrgBtn" iconCls="icon-mag"
						onclick="onselect_2" tooltip="查询" plain="true">查询</a>
				</span><a width="100px"></a> &nbsp;&nbsp;<span id="separatorId2"
					class="separator"> <a class="mini-button" id="addBtn"
						iconCls="icon-add" plain="true" onclick="add">新增</a><a
						class="mini-button" id="employBtn" iconCls="icon-ok" plain="true"
						onclick="employ(1)">入职</a><a class="mini-button" id="deleteBtn"
						iconCls="icon-remove" plain="true" onclick="employ(0)">离职</a>
					<a
					class="mini-button" id="exportBtn" iconCls="icon-excel"
					plain="true" onclick="exportExcel">Excel导出</a></span><span
					id="separatorId3" class="separator"> <a href="javascript:;" class="file"
						id="importBtn">Excel 导入 <input
							accept=".xls,.xlsx"
							name="fileB" type="file" id="fileId" />
					</a></span></td>
				<td style="width: 80px; height: 100%;">
					<div class="pageStatContainer">
						<div id="pageStatBtn_list"
							class="pageStat pageStatList pageStatListPress">
							<p>1</p>
						</div>
						<div id="pageStatBtn_form" class="pageStat pageStatForm">
							<p>2</p>
						</div>
						<div id="pageStatBtn_split" class="pageStat pageStatSplit">
							<p>3</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="400" showCollapseButton="true"
				style="padding: 0px;">
				<div class="mini-fit">
					<div class="mini-splitter" style="width: 100%; height: 100%;">
						<div size="260px" showCollapseButton="true">
							<div id="treegrid1" class="mini-treegrid"
								style="height: 100%; width: 100%;" showTreeIcon="true"
								borderStyle="border:1;" onbeforeload="treeBeforeLoad"
								pagesize="50" sizeList="[50,100,200,500]" showPager="false"
								treeColumn="OrgName" idField="OrgNo"
								ondrawcell="ondatagridDrawCell" onrowclick="orgSelect"
								parentField="ParentNo" resultAsTree="false" expandOnLoad="true"
								showPageInfo="false" showFilterRow="true">
								<div property="columns">
									<div type="checkcolumn" field="Action" width="70px"
										headerAlign="center" align="center">
										<a class="mini-button" property="filter" id="removeBtn"
											iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch()">清除
										</a>
									</div>
									<div name="OrgName" field="OrgName" width="100%"
										headerAlign="center" align="left" allowSort="true">
										企业名称<input id="orgFilter" property="filter"
											class="mini-buttonedit searchbox" style="width: 100%;"
											onbuttonclick="onselect" emptyText="筛选..."
											onenter="onselect_1" />
									</div>
								</div>
							</div>
						</div>
						<div showCollapseButton="true">
							<div id="datagrid2" class="mini-datagrid gridFull"
								borderStyle="border:1;" showReloadButton="true" pagesize="100"
								sizeList="[20,50,100,200]" allowCellWrap="true"
								allowHeaderWrap="true" idField="No" multiSelect="true"
								showPager="true" allowAlternating="true"
								ondrawcell="ondatagrid1DrawCell_2"
								onrowdblclick="gridRowDbClick_2"
								style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
								collapseGroupOnLoad="false" showColumnsMenu="true"
								showFilterRow="true" onshowrowdetail="onShowRowDetail">
								<div property="columns">
									<div type="indexcolumn" width="40px"></div>
									<div type="checkcolumn" width="40px" align="center"></div>
									<div field="Action" width="70px" headerAlign="center"
										align="center">
										<a class="mini-button" property="filter" id="removeBtn"
											iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch_2">清除
										</a>
									</div>
									<div field="Nature" width="60px" headerAlign="center"
										align="center" allowSort="true">
										性质<input id="filter0" property="filter" class="mini-combobox"
											style="width: 100%;" data="natureData"
											onValueChanged="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="CardID" width="140px" headerAlign="center"
										align="left" allowSort="true">
										身份证号<input id="filter1" property="filter"
											class="mini-buttonedit searchbox" style="width: 100%;"
											onbuttonclick="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="UserName" width="65px" headerAlign="center"
										align="left" allowSort="true">
										姓名<input id="filter2" property="filter"
											class="mini-buttonedit searchbox" style="width: 100%;"
											onbuttonclick="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="Sex" width="45px" headerAlign="center"
										align="center" allowSort="true">
										性别<input id="filter3" property="filter" class="mini-combobox"
											style="width: 100%;" data="sexData"
											onValueChanged="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="SourceName1" width="65px" headerAlign="center"
										align="left" allowSort="true">
										来源<input id="filter4" property="filter"
											class="mini-buttonedit searchbox" style="width: 100%;"
											onbuttonclick="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="EmployTypeName" width="60px" headerAlign="center"
										align="left" allowSort="true">
										工种<input id="filter5" property="filter" class="mini-combobox"
											textField="EmployType" valueField="TypeNo"
											style="width: 100%;"
											url="<c:url value='/common/type/employ_type'></c:url>"
											onValueChanged="onselect_2" emptyText="筛选..."
											onenter="onselect_2" />
									</div>
									<div field="CheckInDay" width="60px" headerAlign="center"
										align="right" allowSort="true">考勤天数</div>
									<div field="CheckIn" width="140px" headerAlign="center"
										align="center" allowSort="true">考勤</div>
									<div field="EmployTime" width="90px"
										dateFormat="yyyy-MM-dd" headerAlign="center"
										align="center" allowSort="true">入职时间</div>
									<div field="LeaveTime" width="110px"
										dateFormat="yyyy-MM-dd HH:mm" headerAlign="center"
										align="center" allowSort="true">离职时间</div>
									<div name="emptyCol" width='100%' headerAlign="center"
										align="center" cellStyle="padding:0;"></div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="false"
				style="overflow: hidden;">
				<iframe id="detailPan" class="subPageFrame" frameborder="0">
				</iframe>
			</div>
		</div>
	</div>
	<!-- <div id="htmlContent" style="padding-left: 10px; display: none;">
		考勤天数： <input id="workDays" class="mini-textbox" enabled="true"
			required="true" vtype="float" emptyText="请输入考勤天数"
			style="width: 50%; margin-top: 5px;" onvaluechanged="daysEnter"></input> <span
			style="color: red;">&nbsp;天</span>
	</div> -->
	<div id="htmlContent" style="padding-left: 10px; display: none;">
		导出文件名： <input id="fileNameId" class="mini-textbox" enabled="false"
			emptyText="请输入导出文件名" style="width: 86%; margin-top: 5px;"></input> <span
			style="color: red;">&nbsp;.xls</span>
	</div>


	<script type="text/javascript">
		mini.parse();

		mini_debugger = false;
		var isKeepStat3 = false;

		var rootPath = '${rootPath}';
		var userLevel = '${userLevel}';
		var userCard = '${userCard}';
		var type = 1;

		var filterHelper = gridFilter();
		var filterHelper2 = gridFilter();

		var typeBtn = mini.get("typeBtn");
		var datagrid1 = mini.get("treegrid1");
		var datagrid2 = mini.get("datagrid2");
		var splitpan = mini.get("splitterPan");
		var orgFilter = mini.get("orgFilter");
		var filter0 = mini.get("filter0");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter3 = mini.get("filter3");
		var filter4 = mini.get("filter4");
		var filter5 = mini.get("filter5");
		var orgNo = null;
		var orgName = null;
		var state = 1;

		var starting = mini.get("starting");
		var ending = mini.get("ending");

		$(function() {
			$(".pageStat").hover(function() {
				$(this).addClass("hoverStyle");
			}, function() {
				$(this).removeClass("hoverStyle");
			});
			$(".pageStat").click(
					function() {
						$this = $(this);
						var value = $this.find("p").first().html();
						if (value == 1) {
							splitpan.collapsePane(2);
							$this.addClass("pageStatListPress");
							$this.next().removeClass("pageStatFormPress")
									.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status1Show();
						}
						if (value == 2) {
							splitpan.collapsePane(1);
							$this.addClass("pageStatFormPress");
							$this.prev().removeClass("pageStatListPress");
							$this.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status2Show();
						}
						if (value == 3) {
							splitpan.expandPane(1);
							splitpan.expandPane(2);
							$this.addClass("pageStatSplitPress");
							$this.prev().removeClass("pageStatFormPress")
									.prev().removeClass("pageStatListPress");
							isKeepStat3 = true;
							status3Show();
						}
					});
			status1();
			loadGrid1();
		});
		function checkMap() {
			status2();
			$("#check").hide();
			$('#detailPan').css('height', '100%').css('width', '100%').attr('src',
					'<c:url value="/public/map" />');
		}
		function onselect_1() {
			var filterValue0 = orgFilter.getValue();
			filterHelper.clearFilterData();
			if (filterValue0 != "") {
				var filterdata = filterHelper.formFilterData("OrgName",
						filterValue0, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function onselect_2() {
			var filterValue0 = filter0.getValue();
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			var filterValue3 = filter3.getValue();
			var filterValue4 = filter4.getValue();
			var filterValue5 = filter5.getValue();
			var filterStarting = starting.getValue();
			var filterEnding = ending.getValue();
			filterHelper2.clearFilterData();
			
			if (filterStarting && filterEnding && filterStarting > filterEnding) {
				mini.alert('结束日期不能小于开始日期！');
				return;
			}
			if (filterValue0 != "") {
				var filterdata = filterHelper.formFilterData("Nature",
						filterValue0, '', 'EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue1 != "") {
				var filterdata = filterHelper.formFilterData("CardID",
						filterValue1, '', 'CONTAIN', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue2 != "") {
				var filterdata = filterHelper.formFilterData("UserName",
						filterValue2, '', 'CONTAIN', 'AND');
				console.info(filterdata);
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue3 != "") {
				var filterdata = filterHelper.formFilterData("Sex",
						filterValue3, '', 'EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue4 != "") {
				var filterdata = filterHelper.formFilterData("SourceName1",
						filterValue4, '', 'CONTAIN', 'AND');
				console.info(filterdata);
				filterHelper2.addFilterData(filterdata);
			}
			if (filterValue5 != "") {
				var filterdata = filterHelper.formFilterData("EmployType",
						filterValue5, '', 'EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterStarting != "") {
				var filterdata = filterHelper.formFilterData("EmployTime",
						filterStarting, '', 'GREATER_EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			if (filterEnding != "") {
				var filterdata = filterHelper.formFilterData("EmployTime",
						filterEnding, '', 'LESS_EQUALS', 'AND');
				filterHelper2.addFilterData(filterdata);
			}
			loadGrid2(orgNo);

		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var url = "<c:url value='/org/list4user' />";
			datagrid1.setUrl(url);
			datagrid1.load(postData, function() {
				var row = datagrid1.getRow(0);
				if (row) {
					datagrid1.setSelected(row);
					orgNo = row.OrgNo;
					orgName = row.OrgName;
					$('.nameTitle').html(orgName);
					onselect_2();
				}
			});
		}
		function orgSelect() {
			var row = datagrid1.getSelected();
			if (!row) {
				return;
			}
			orgNo = row.OrgNo;
			if (!orgNo) {
				mini.alert('数据有误 ，请联系管理员处理！');
				return;
			}
			orgName = row.OrgName;
			$('.nameTitle').html(orgName);
			onselect_2();
		}
		function loadGrid2(orgNo) {
			var filterData = filterHelper2.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			if(!state){
				state = typeBtn.getValue();
			}
			var url = "<c:url value='/user/list/' />" + orgNo + '/' + state;
			console.info(postData);
			datagrid2.load(url);
			datagrid2.load(postData);
		}
		function chageState() {
			state = this.getValue();
			if(state == 1){
				$("#deleteBtn").show();
				$("#employBtn").hide();
			}else{
				$("#deleteBtn").hide();
				$("#employBtn").show();
			}
			var row = datagrid1.getSelected();
			if (!row || !row.OrgNo) {
				mini.alert('请选择企业！');
				return;
			}
			orgNo = row.OrgNo;
			onselect_2();
		}
		function removeSearch() {
			orgFilter.setValue();
			orgFilter.setText();
			filterHelper.clearFilterData();
			loadGrid1();
		}
		function removeSearch_2() {
			filter0.setValue();
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filter3.setValue();
			filter4.setValue();
			filter4.setText();
			filter5.setValue();
			starting.setValue();
			starting.setText();
			ending.setValue();
			ending.setText();
			filterHelper2.clearFilterData();
			loadGrid2(orgNo);
		}
		function ondatagridDrawCell(e) {
			var field = e.field;
			var row = e.row;
			var grade = row.Grade;
			var cellCls = null;
			switch (grade) {
			case 1:
				cellCls = "deepDark";
				break;
			case 2:
				cellCls = "normalDark";
				break;
			default:
				cellCls = "lowDark";
				break;
			}
			e.cellCls = cellCls;
		}
		function ondatagrid1DrawCell_2(e) {
			var row = e.row;
			var field = e.field;
			if (field == "Action") {
				var id = row.EmployId;
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:update('+id+')">[详细]</a>';
			}

			if (field == "Sex") {
				var value = e.value;
				if (typeof value=='number') {
					e.cellHtml = (value == 1) ? '男' : '女';
				}
			}
			if (field == "Nature") {
				var value = e.value;
				if(typeof value == 'number'){
					if(value==1){
						e.cellHtml =  '长期';
					}else{
						e.cellHtml =  '短期';
					}
				}
			}
			if (field == "CheckIn") {
				var value = row.Nature;
				var uState = row.State;
				if(typeof value == 'number' && (value==0||value=='0') && uState){//短期工签到
					var id = row.EmployId;
					var checked = row.Checked;
					if(checked){
						e.cellHtml = '<span style="color:red;">已考勤</span><a class="aTagUnderLine" href="javascript:checkIn('+id+',1)">[继续考勤]</a><a class="aTagUnderLine" href="javascript:checkInDetail('+id+')">[明细]</a>';
					}else{
						e.cellHtml = '<a class="aTagUnderLine" href="javascript:checkIn('+id+',0)">[考勤]</a><a class="aTagUnderLine" href="javascript:checkInDetail('+id+')">[明细]</a>';
					}
				}
			}
		}
		function treeBeforeLoad(e) {
			var filterData = filterHelper.getFilterData();
			e.data.filterdata = mini.encode(filterData);
		}

		function status1() {
			if (!isKeepStat3) {
				$("#pageStatBtn_list").click();
			}
		}
		function status2() {
			if (!isKeepStat3) {
				$("#pageStatBtn_form").click();
			}
		}
		function status3() {
			$("#pageStatBtn_split").click();
		}
		function status1Show() {
			$('#rebackBtn').hide();
			$('#typeBtn').show();
			$('#resetBtn').show();
			$("#check").show();
			$("#separatorId").show();
			$("#separatorId2").show();
			$("#addBtn").show();
			if(state == 1){
				$("#deleteBtn").show();
				$("#employBtn").hide();
			}else{
				$("#deleteBtn").hide();
				$("#employBtn").show();
			}
			if(userLevel == '9'){
				$("#separatorId3").show();
			}else{
				$("#separatorId3").hide();
			}
		}
		function status2Show() {
			$('#rebackBtn').show();
			$('#typeBtn').hide();
			$('#resetBtn').hide();
			$("#check").hide();
			$("#separatorId3").hide();
			$('#separatorId').hide();
			$('#separatorId2').hide();
			$("#addBtn").hide();
			$("#deleteBtn").hide();
			$("#employBtn").hide();
		}
		function status3Show() {
			$('#rebackBtn').hide();
			$('#typeBtn').show();
			$('#resetBtn').show();
			$("#check").hide();
			$("#separatorId3").hide();
			$('#separatorId').hide();
			$('#separatorId2').hide();
			$("#addBtn").hide();
			$("#deleteBtn").hide();
			$("#employBtn").hide();
		}
		function reloadList() {
			datagrid2.reload();
		}

		function FormatDate(strTime) {
			var date = new Date(strTime);
			return date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
					+ date.getDate() + " " + date.getHours() + ":"
					+ date.getMinutes();
		}
		
		function add() {
			var row = datagrid1.getSelected();
			if (!row) {
				mini.alert('请选择企业！');
				return;
			}
			var orgNo = row.OrgNo;
			if (!orgNo) {
				mini.alert('企业数据有误，请联系管理员处理！');
				return;
			}else if(orgNo == 'all'){
				mini.alert('请选择企业！');
				return;
			}
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr(
					'src', '<c:url value="/user/add/" />'+orgNo);
		}
		function gridRowDbClick_2(e){
			var row = e.row;
			if(!row) return;
			update(row.EmployId);
		}
		function update(id) {
			status2();
			$('#detailPan').css('height', '100%').css('width', '100%').attr(
					'src', '<c:url value="/user/edit/" />'+id);
		}
		//入职与离职
		function employ(type) {
			var rows = datagrid2.getSelecteds();
			var text = null;
			if(type == 1){
				text = "重新入职到本公司"
			}else if(type == 0){
				text = "从本公司离职"
			}else{
				return;
			}
			
			if (rows.length <= 0) {
				mini.alert("请选择需要"+text+"的人员！");
				return;
			}
			mini.confirm("确定将所选择人员"+text+"？", "确定？", function(action) {
				if (action == "ok") {
					var id= "";
        			for(var i = 0; i<rows.length;i++){
    					if(id == ""){
    						id = rows[i].EmployId;
    					}else{
    						id += ","+rows[i].EmployId;
    					}
        			}
					var url = rootPath + "/user/employ/"+type;
					$.ajax({
						url : url,
						method : "post",
						dataType : "json",
						data : {
							"employIds" : id
						},
						success : function(data) {
							if (data) {
								top.commonTools.showTip("操作成功！", 1);
								datagrid2.reload();
							} else {
								top.commonTools.showTip("操作失败！", 2);
								datagrid2.reload();
							}
						},
						error : function() {
							top.commonTools.showTip("操作发生错误！", 2);
						}

					});
				}
			});
		}
		//批量考勤
		function checkInAll() {
			var ids = null;
			var rows = datagrid2.findRows(function(row){
			    if(row.Nature == 0){
			    	if(ids != null){
			    		ids += ',';
			    	}
			    	ids += row.EmployId;
			    	return true;
			    }
			});
			if (rows.length <= 0) {
				mini.alert("请选择需要考勤的短期工！");
				return;
			}
			checkIn(ids);
		}
		//考勤
		function checkIn(ids,checked) {
			if(checked){
				mini.confirm("今日已考勤，是否继续？", "确定？", function(action) {
					if (action == "ok") {
						mini.prompt("请输入考勤天数(不填默认为1天)：", "考勤", function(action, value){
							if (action == "ok") {
								var days = 1;
								if(value){
									days = parseFloat(value);
									if(!days){
										mini.alert("请输入数字！");
										return;
									}
								}
								checkInRecord(ids,days);
			                } else {
			                	//top.commonTools.showTip("取消！", 2);
			                }
						}, false);
					}
				});
			}else{
				mini.prompt("请输入考勤天数(不填默认为1天)：", "考勤", function(action, value){
					if (action == "ok") {
						var days = 1;
						if(value){
							days = parseFloat(value);
							if(!days){
								mini.alert("请输入数字！");
								return;
							}
						}
						checkInRecord(ids,days);
	                } else {
	                	//top.commonTools.showTip("取消！", 2);
	                }
				}, false);
			}
		}
		function checkInRecord(ids,days){
			$.ajax({
				url : rootPath + "/user/checkIn",
				method : "post",
				dataType : "json",
				data : {
					"employIds" : ids,
					"days" : days
				},
				success : function(data) {
					if (data) {
						top.commonTools.showTip("操作成功！", 1);
						datagrid2.reload();
					} else {
						top.commonTools.showTip("操作失败！", 2);
						datagrid2.reload();
					}
				},
				error : function() {
					top.commonTools.showTip("操作发生错误！", 2);
				}

			});
		}
		// 批量导入
		$("#importBtn").click(function() {
			var messageid = mini.loading("请勿操作，导入中...", "Loading");
			$('#fileId').fileupload({
				dataType : 'html',//数据类型：json
				url : rootPath + '/attach/upload/fileB/无/excel/' + userCard,//上传地址
				formData : {
					name : 'fileB'
				},
				add : function(e, data) {
					data.submit();
				},
				done : function(e, data) {
					//若上传成功则调用函数处理上传的excel
					if (messageid) {
						mini.hideMessageBox(messageid);
					}
					var param = successDataTransform(data.result);
					if (param.isSuccess) {
						excelImport(param.errorInfo);
					}
				}
			});
		});
		function excelImport(filePath) {
			var messageid = mini.loading("正在导入...", "Loading");
			$.ajax({
				url : rootPath + '/excel/import',//excel处理地址
				method : "post",
				dataType : "json",
				data : {
					"filePath" : filePath
				},
				success : function(data) {
					if (data) {
						top.commonTools.showTip("操作成功！", 1);
						datagrid2.reload();
					} else {
						top.commonTools.showTip("操作失败！", 2);
						datagrid2.reload();
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
					if (messageid) {
						mini.hideMessageBox(messageid);
					}
				},
				error : function() {
					top.commonTools.showTip("操作发生错误！", 2);
				}

			});
		}
		function daysEnter(){
			top.commonTools.showTip(this.getValue(), 1);
		}
		function checkInDetail(id){
			var url = "<c:url value='/user/checkInDetail/' />"+id;
			mini.open({
				url : url,
				title : "考勤记录",
				width : 800,
				height : 600,
				onload : function() {
					/* var iframe = this.getIFrameEl();
					var data = {
					}; */
					//iframe.contentWindow.SetData(data);
				},
				ondestroy : function(action) {
					if (action == 'ok') {
						//reloadList();
					}
				}
			});
		}
		function exportExcel() {

			var htmlContent = document.getElementById("htmlContent");
			var fileNameId = mini.get("fileNameId");
			/* var row = datagrid1.getSelected(); */
			var reportName = '员工资料';
			fileNameId.setValue(reportName);
			//fileNameId.text = reportName;
			fileNameId.focus();
			var clone = htmlContent.cloneNode(true);
			clone.style.display = "";
			
			var filterData = filterHelper2.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}

			mini.showMessageBox({
				width : 250,
				title : "员工资料导出",
				buttons : [ "ok", "cancel" ],
				message : "自定义Html",
				html : clone,
				showModal : false,
				callback : function(action) {
					if (action == "ok") {
						var fileName = fileNameId.value;
						if (!fileName) {
							fileName = reportName;
						}
						fileName = encodeURI(fileName); //编码
						postData = encodeURI(postData.filterdata); //编码
						var url = rootPath + '/excel/export/user/'+orgNo+'/' + fileName+'/'+postData;
						window.open(url);
					}
				}
			});
		}
	</script>
</body>
</html>